#! /bin/sh

#---------------------------------------------------------------------
#                             load-config                             
# 
# This is the opportunity for the template to modify the package
# configuration stored in fw-pkgin/config, e.g., add the template to the
# build dependencies.
# 
# The convention is that every program that wants to load fw-pkgin/config
# will go through template/$template/load-config
#---------------------------------------------------------------------

#---------------------------------------------------------------------
#                           chicken and egg                           
#---------------------------------------------------------------------

test -f "${FW_ROOT}/share/fw/sh/fw-find.sh" && fws="${FW_ROOT}/share/fw/sh/fw-find.sh"
test -f "fw/sh/fw-find.sh" && fws="fw/sh/fw-find.sh"
test -f "fw.local/sh/fw-find.sh" && fws="fw.local/sh/fw-find.sh"
test ! -z "$fws" || {
  echo "Cxx/load-config: fatal: can't locate fw-find.sh" 1>&2
  exit 1
}

. "$fws"

#---------------------------------------------------------------------
#                              routines                               
#---------------------------------------------------------------------

fw_source "Cxx/load-config" "sh/fw-exec.sh"
fw_source "Cxx/load-config" "sh/parse-args.sh"
fw_source "Cxx/load-config" "sh/validate-args.sh"

#---------------------------------------------------------------------
#                                main                                 
#---------------------------------------------------------------------

parse_args "Cxx/load-config" "$@"

validate_args "Cxx/load-config" "" ""

# default behavior: add the package providing the template to the build
# dependencies

fw_exec "template/C/load-config" |                          \
perl -pe 's%FW_PACKAGE_BUILD_DEPENDS="(.*)"%FW_PACKAGE_BUILD_DEPENDS="fw-template-cxx, $1"%; s%, "%"%; s%#(.*)%%;'
